package parse;

import model.model;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.List;

public class priceParse_1 {
    public static List<model> getData(String factory, String brand, String Car_big, String html){
        List<model> data = new ArrayList<model>();
        Document document = Jsoup.parse(html);
        Elements elements_all = document.select("div[class=\"crumbs-txt\"]").select("a");
        if(elements_all.size() == 6){
            factory = elements_all.get(3).text();
            brand = elements_all.get(2).text();
            Car_big = elements_all.get(4).text();
        }
        if(elements_all.size() == 5){
            factory = elements_all.get(2).text();
            brand = elements_all.get(2).text();
            Car_big = elements_all.get(3).text();
        }


        Elements elements = document.select("tr[class=\"trForPic\"]").select("td");
        if(!document.select("tr:contains(上市时间)").isEmpty()){ //eles类似于集合,所以用isEmpty来判断
            // && !document.select("tr:contains(深圳参考价)").isEmpty() && !document.select("tr:contains(车型级别)").isEmpty()
            //                && !document.select("tr:contains(混合工况油耗[L/100km])").isEmpty()
            //                && !document.select("tr:contains(变速箱类型)").isEmpty() && !document.select("tr:contains(整备质量[kg])").isEmpty() && !document.select("tr:contains(排量(mL))").isEmpty()
            //                && !document.select("tr:contains(燃油标号)").isEmpty() && !document.select("tr:contains(发动机)").isEmpty()

            for(int i = 0; i < elements.size(); i++) {
                model Model = new model();
                Model.setBrand(brand);
                //System.out.println(elements.get(i).select("dd").select("a").get(0).text());
                Model.setFactory(factory);
                Model.setCar_big(Car_big);
                if (elements.get(i).select("dd").select("a").size()>1) {
                    Model.setCar_small(elements.get(i).select("dd").select("a").get(0).text());
                    Model.setFactory_price(elements.get(i).select("dd").select("a").get(1).text());
                }else {
                    break;
                }
                if(!document.select("tr:contains(深圳参考价)").isEmpty()){Model.setSHENZHEN_price(document.select("tr:contains(深圳参考价)").select("td").get(i).text());}else {Model.setSHENZHEN_price(null);}
                if(!document.select("tr:contains(上市时间)").isEmpty()){Model.setTime(document.select("tr:contains(上市时间)").select("td").get(i).text());}else {Model.setTime(null);}
                if(!document.select("tr:contains(车型级别)").isEmpty()){Model.setCar_level(document.select("tr:contains(车型级别)").select("td").get(i).text());}else {Model.setCar_level(null);}
                if(!document.select("tr:contains(车身型式)").isEmpty()){Model.setCar_body(document.select("tr:contains(车身型式)").select("td").get(i).text());}else {Model.setCar_body(null);}
                if(!document.select("tr:contains(动力类型)").isEmpty()){Model.setDynamic_type(document.select("tr:contains(动力类型)").select("td").get(i).text());}else {Model.setDynamic_type(null);}
                if(!document.select("tr:contains(发动机)").isEmpty()){Model.setEngine(document.select("tr:contains(发动机)").select("td").get(i).text());}else {Model.setEngine(null);}
                if(!document.select("tr:contains(最大功率/最大扭矩)").isEmpty()){Model.setMaximum_power_torque(document.select("tr:contains(最大功率/最大扭矩)").select("td").get(i).text());}else {Model.setMaximum_power_torque(null);}
                if(!document.select("tr:contains(变速箱类型)").isEmpty()){Model.setTransmission_type(document.select("tr:contains(变速箱类型)").select("td").get(i).text());}else {Model.setTransmission_type(null);}
                if(!document.select("tr:contains(混合工况油耗[L/100km])").isEmpty()){Model.setFuel_consumption(document.select("tr:contains(混合工况油耗[L/100km])").select("td").get(i).text());}else {Model.setFuel_consumption(null);}
                if(!document.select("tr:contains(0-100km/h加速时间[s])").isEmpty()){Model.setAcceleration_time(document.select("tr:contains(0-100km/h加速时间[s])").select("td").get(i).text());}else {Model.setAcceleration_time(null);}
                if(!document.select("tr:contains(最高车速[km/h])").isEmpty()){Model.setTop_speed(document.select("tr:contains(最高车速[km/h])").select("td").get(i).text());}else {Model.setTop_speed(null);}
                if(!document.select("tr:contains(环保标准)").isEmpty()){Model.setEnvironmental_standard(document.select("tr:contains(环保标准)").select("td").get(i).text());}else {Model.setEnvironmental_standard(null);}
                if(!document.select("tr:contains(保修政策)").isEmpty()){Model.setWarranty_policy(document.select("tr:contains(保修政策)").select("td").get(i).text());}else {Model.setWarranty_policy(null);}
                if(!document.select("tr:contains(长×宽×高[mm])").isEmpty()){Model.setLength_width_height(document.select("tr:contains(长×宽×高[mm])").select("td").get(i).text());}else {Model.setLength_width_height(null);}
                if(!document.select("tr:contains(轴距[mm])").isEmpty()){Model.setWheelbase(document.select("tr:contains(轴距[mm])").select("td").get(i).text());}else {Model.setWheelbase(null);}
                if(!document.select("tr:contains(整备质量[kg])").isEmpty()){Model.setWeight(document.select("tr:contains(整备质量[kg])").select("td").get(i).text());}else {Model.setWeight(null);}
                if(!document.select("tr:contains(座位数[个])").isEmpty()){Model.setSeats_number(document.select("tr:contains(座位数[个])").select("td").get(i).text());}else {Model.setSeats_number(null);}
                if(!document.select("tr:contains(行李厢容积[L])").isEmpty()){Model.setLuggage_capacity(document.select("tr:contains(行李厢容积[L])").select("td").get(i).text());}else {Model.setLuggage_capacity(null);}
                if(!document.select("tr:contains(油箱容积[L])").isEmpty()){Model.setTank_capacity(document.select("tr:contains(油箱容积[L])").select("td").get(i).text());}else {Model.setTank_capacity(null);}
                if(!document.select("tr:contains(前轮胎规格)").isEmpty()){Model.setFront_tire_specification(document.select("tr:contains(前轮胎规格)").select("td").get(i).text());}else {Model.setFront_tire_specification(null);}
                if(!document.select("tr:contains(后轮胎规格)").isEmpty()){Model.setRear_tire_specification(document.select("tr:contains(后轮胎规格)").select("td").get(i).text());}else {Model.setRear_tire_specification(null);}
                if(!document.select("tr:contains(备胎)").isEmpty()){Model.setSpare_tire(document.select("tr:contains(备胎)").select("td").get(i).text());}else {Model.setSpare_tire(null);}
                if(!document.select("tr:contains(最小转弯直径[m])").isEmpty()){Model.setMinimum_turning_diameter(document.select("tr:contains(最小转弯直径[m])").select("td").get(i).text());}else {Model.setMinimum_turning_diameter(null);}
                if(!document.select("tr:contains(最小离地间隙[mm])").isEmpty()){Model.setMinimum_ground_clearance(document.select("tr:contains(最小离地间隙[mm])").select("td").get(i).text());}else {Model.setMinimum_ground_clearance(null);}
                if(!document.select("tr:contains(排量(mL))").isEmpty()){Model.setDisplacement(document.select("tr:contains(排量(mL))").select("td").get(i).text());}else {Model.setDisplacement(null);}
                if(!document.select("tr:contains(最大功率[kW])").isEmpty()){ Model.setMaximum_power(document.select("tr:contains(最大功率[kW])").select("td").get(i).text());}else {Model.setMaximum_power(null);}
                if(!document.select("tr:contains(最大马力[Ps])").isEmpty()){Model.setMaximum_horsepower(document.select("tr:contains(最大马力[Ps])").select("td").get(i).text());}else {Model.setMaximum_horsepower(null);}
                if(!document.select("tr:contains(最大功率转速[rpm])").isEmpty()){Model.setMaximum_power_speed(document.select("tr:contains(最大功率转速[rpm])").select("td").get(i).text());}else {Model.setMaximum_power_speed(null);}
                if(!document.select("tr:contains(最大扭矩[N.m])").isEmpty()){Model.setMaximum_torque(document.select("tr:contains(最大扭矩[N.m])").select("td").get(i).text());}else {Model.setMaximum_torque(null);}
                if(!document.select("tr:contains(最大扭矩转速[rpm])").isEmpty()){Model.setMaximum_torque_speed(document.select("tr:contains(最大扭矩转速[rpm])").select("td").get(i).text());}else {Model.setMaximum_torque_speed(null);}
                if(!document.select("tr:contains(供油方式)").isEmpty()){Model.setOil_supply_way(document.select("tr:contains(供油方式)").select("td").get(i).text());}else {Model.setOil_supply_way(null);}
                if(!document.select("tr:contains(燃油标号)").isEmpty()){Model.setFuel_label(document.select("tr:contains(燃油标号)").select("td").get(i).text());}else {Model.setFuel_label(null);}
                if(!document.select("tr:contains(变速箱类型)").isEmpty()){Model.setTransmission_type1(document.select("tr:contains(变速箱类型)").select("td").get(i).text());}else {Model.setTransmission_type1(null);}
                if(!document.select("tr:contains(挡位个数)").isEmpty()){Model.setBlock_number(document.select("tr:contains(挡位个数)").select("td").get(i).text());}else {Model.setBlock_number(null);}
                data.add(Model);





            }
        }





        return data;






    }
}
